package util;

import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;

public class ServletUtil extends HttpServlet{
	
	public void init(ServletConfig config)throws ServletException{
		
		super.init();
	}
	
	public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
		String param=request.getParameter("p");
		//doPost(request, response);
		read(request, response, param);
	}
	
	public void doPost(HttpServletRequest resquest,HttpServletResponse response)throws ServletException,IOException{
		
	}
	
	private void read(HttpServletRequest request,HttpServletResponse response,String p)throws ServletException,IOException{
		
		AppConfig app=new AppConfig(request,"AppConfig.properties");
		PrintWriter out=response.getWriter();
		String[] values=app.readArray(p);
		out.println("<html>");
		out.println("<head><title>Simple Servlet</title></head>");
		out.println("<body>");
		out.println("Parameter: "+p+"<br/>");
		for(int i=0;i<values.length;i++){
			out.println(i+1+" : "+ values[i]+"<br/>");
		}
		out.println("</body></html>");
		out.close();
	}

}
